import 'dart:async';
import 'dart:io';
import 'package:core/core.dart';

///应用第三方SDK 管理
///主要管理会获取用户敏感信息的 三方SDK
class AppSdkManager {
  ///初始化SDKs
  static initSDKs() async {
    try {
      _initBugly();
      _initShareSDK();
      AppConfig.deviceId = await DeviceUtil.deviceId(); //用户设备ID，初始化时获取，方便后续调用
    } catch (e) {
      LogUtil.e('init sdk error is $e');
    }
  }

  static bool hasBuglyInited = false;

  ///初始化腾讯bugly
  static Future<void> _initBugly() async {
    //不是发布版本不记录
    if (!AppConfig.isRelease) return;
    BuglyParams? buglyParams = AppConfig.bugly;
    if (buglyParams != null) {
      // FzBuglyPlugin.init(
      //     iosAppId: buglyParams.iosAppId,
      //     androidAppId: buglyParams.androidAppId);
      hasBuglyInited = true;
    }
  }

  static bool _hasShareSDKInited = false;

  ///shareSDK 是否初始化
  static bool get hasShareSDKInited {
    if (Platform.isIOS) return _hasShareSDKInited;
    return true;
  }

  static bool _hasTTSInitialized = false;

  /// shareSDK iOS初始化 微信、微博、QQ
  static Future<void> _initShareSDK() async {
    AppShareParams? shareParams = AppConfig.share;

    if (shareParams != null) {
      // if (Platform.isIOS) {
      //   ShareSDKRegister register = ShareSDKRegister();
      //   register.setupWechat(
      //     shareParams.wechatParams?["appId"],
      //     shareParams.wechatParams?["appSecret"],
      //     shareParams.wechatParams?["path"],
      //   );
      //   register.setupQQ(
      //       shareParams.qqParams?["appId"], shareParams.qqParams?["appKey"]);
      //   register.setupDingTalk(shareParams.dingParams?['appId']);
      //   register.setupSinaWeibo(
      //       shareParams.sinaParams?["appKey"],
      //       shareParams.sinaParams?["appKey"],
      //       shareParams.sinaParams?["redirectUrl"],
      //       shareParams.sinaParams?["universalLink"]);
      //   await SharesdkPlugin.regist(register);
      // }
      //
      // //同意协议 不然报错
      // SharesdkPlugin.uploadPrivacyPermissionStatus(1, (success) {
      //   LogUtil.v('ShareSDK 同步隐私协议:  返回 ${success}');
      // });
      _hasShareSDKInited = true;
    }
  }
}
